<template>
  <div>
    <el-dialog title="菜单" :visible.sync="dialogData.visible">
      <el-form :model="form" class="items-in-form">
        <div class="right-radio">
          <span class="right-title">权限组名称</span>
          <el-radio disabled v-model="radio" label="菜单">菜单</el-radio>
          <el-radio disabled v-model="radio" label="权限点">权限点</el-radio>
        </div>
        <el-form-item label="权限组名称" :label-width="formLabelWidth">
          <select-tree
            v-model="selected"
            :options="menuList"
            :props="defaultProps"
          />
        </el-form-item>
        <div class="normal-input">
          <el-form-item label="权限代码" :label-width="formLabelWidth">
            <el-input
              v-model="dialogData.rowInfo.code"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          <el-form-item label="权限标题" :label-width="formLabelWidth">
            <el-input
              v-model="dialogData.rowInfo.title"
              autocomplete="off"
            ></el-input>
          </el-form-item>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="$emit('closeDialog', false)">取 消</el-button>
        <el-button type="primary" @click="changeMenu">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import selectTree from '@/utils/components/select-tree'
import { changeMenu } from '@/api/menu'
export default {
  name: 'fixDialog',
  components: {
    selectTree
  },
  props: {
    dialogData: {
      required: true
    },
    menuList: {
      required: true
    }
  },
  data() {
    return {
      rowInfo: {},
      // 默认选中值
      selected: '',
      // 数据默认字段
      defaultProps: {
        parent: 'pid', // 父级唯一标识
        value: 'code', // 唯一标识
        label: 'title', // 标签显示
        children: 'childs' // 子级
      },
      radio: '菜单',
      form: {
        name: '',
        region: '',
        date1: '',
        date2: '',
        delivery: false,
        type: [],
        resource: '',
        desc: ''
      },
      formLabelWidth: '120px'
    }
  },
  created() {},
  methods: {
    async changeMenu() {
      const dataOfChange = {
        code: this.selected,
        id: this.dialogData.rowInfo.id,
        is_point: this.dialogData.rowInfo.is_point,
        pid: this.dialogData.rowInfo.pid,
        title: this.dialogData.rowInfo.title
      }
      await changeMenu(dataOfChange)
      this.$message({
        type: 'success',
        message: '修改成功!'
      })
      this.$emit('closeDialog', false)
    }
  }
}
</script>

<style lang="less" scoped>
/deep/ .el-dialog__header {
  background-color: #409eff;
  .el-dialog__title,
  .el-dialog__close {
    color: #fff;
  }
}
.items-in-form {
  .right-radio {
    margin-bottom: 30px;
    .right-title {
      margin: 0 10px 0 38px;
    }
  }
  /deep/ .el-input--suffix {
    width: 300px;
    .el-popper {
      width: 300px;
    }
  }
  .normal-input /deep/ .el-input__inner {
    width: 300px;
  }
}
</style>
